package com.qf.service.impl;

import com.qf.dao.CommunityMapper;
import com.qf.dao.MailboxMapper;
import com.qf.dao.OwnerMapper;
import com.qf.dao.RepairMapper;
import com.qf.pojo.Community;
import com.qf.pojo.Mailbox;
import com.qf.pojo.Owner;
import com.qf.service.MailboxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.crypto.Data;
import java.util.Date;
import java.util.List;

@Service
public class MailboxServiceImpl implements MailboxService {



    @Autowired
    private MailboxMapper mailboxMapper;

    @Autowired
    private CommunityMapper communityMapper;

    @Autowired
    private OwnerMapper ownerMapper;


    @Override
    public List<Mailbox> findByRepairPage() {
        return mailboxMapper.selectByExample(null);
    }

    @Override
    public List<Community> findAllCommunity() {
        return communityMapper.selectByExample(null);
    }

    @Override
    public List<Owner> findAllOwner() {
        return ownerMapper.selectByExample(null);
    }

    @Override
    public void saveOrUpdateMailbox(Mailbox mailbox) {

        if (mailbox.getId() == null) {
            // 新增
            System.out.println("===============" + mailbox);
            Date date = new Date();
            mailbox.setCreatedate(date);
            System.out.println("-============" + mailbox);
            mailboxMapper.insert(mailbox);
        } else {
//            System.out.println("此处调用Service下的修改方法");
            mailboxMapper.updateByPrimaryKey(mailbox);
        }
    }


    @Override
    public Mailbox findByMialboxId(Integer id) {
        return mailboxMapper.selectByPrimaryKey(id);
    }

    @Override
    public void deleteMailbox(Integer id) {
        mailboxMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void deleteByMailboxId(Integer[] ids) {
        mailboxMapper.deleteByRepairId(ids);
    }

    @Override
    public void updateMailboxById(Integer id) {

    }
}
